<template>
  <pageTabelLayout>
    <template #pageHeader>
      <div class="search-form isheader" v-if="headerShow">
        <div>
          <a-form style="width: 100% !important" size="small" :model="queryData" layout="inline">
            <a-form-item label="坯布编号" v-if="permissionStore.hasPermisson('pblb.dclcx') ||
                            permissionStore.hasPermisson('pblb.yclcx')
                            ">
              <a-input allow-clear :style="{ width: '200px' }" class="bacClass" placeholder=""
                       v-model="pageData.dropDownData" @press-enter="huiche"/>
            </a-form-item>
            <a-form-item label="坯布名称" v-if="permissionStore.hasPermisson('pblb.dclcx') ||
                            permissionStore.hasPermisson('pblb.yclcx')
                            ">
              <a-input allow-clear :style="{ width: '200px' }" class="bacClass" placeholder=""
                       v-model="pageData.dropDownData2" @press-enter="huiche"/>
            </a-form-item>
            <!--            <a-form-item label="产品类型" v-if="permissionStore.hasPermisson('pblb.dclcx') ||-->
            <!--              permissionStore.hasPermisson('pblb.yclcx')-->
            <!--              ">-->
            <!--              <a-input allow-clear :style="{ width: '200px' }" class="bacClass" placeholder=""-->
            <!--                v-model="pageData.dropDownData4" @press-enter="huiche" />-->
            <!--            </a-form-item>-->
          </a-form>
        </div>
        <div class="my-tool-bar">
          <Toolbar v-if="shenhebiaoji == 1" :items="[
                        `${permissionStore.hasPermisson('pblb.dclcx') ? '查询' : ''}`,
                        `${permissionStore.hasPermisson('pblb.dclxz') ? '新增' : ''}`,
                        `${permissionStore.hasPermisson('pblb.dclsc') ? '删除' : ''}`,
                        `${permissionStore.hasPermisson('pblb.dclsh') ? '审核' : ''}`,
                    ]" @add="addHandler" @del="deleteHandler" @select="selectHandler" @audit="shenhe('待审核')">
          </Toolbar>
          <Toolbar v-if="shenhebiaoji == 2" :items="[
                        `${permissionStore.hasPermisson('pblb.yclcx') ? '查询' : ''}`,
                        `${permissionStore.hasPermisson('pblb.yclfs') ? '反审' : ''}`,
                    ]" @select="selectHandler" @counter="shenhe('已审核')">
          </Toolbar>
        </div>
      </div>
      <div class="my-divisders">
        <a-divider orientation="center">
          <icon-double-up v-if="headerShow" @click="headerShow = false" :strokeWidth="2" :size="18"/>
          <icon-double-down v-else @click="headerShow = true" :strokeWidth="2" :size="18"/>
        </a-divider>
      </div>
    </template>

    <template #pageTabel>
      <a-tabs   :lazy-load="true" :justify="true" default-active-key="1" @change="handoff">
        <a-tab-pane title="待审核" key="1">
          <a-spin :loading="pageData.pageLoading" tip="加载中" dot
                  style="height: 100%; width: 100%; z-index: 999">
            <AgGridVuesCopys :rowHeight="33" :headerHeight="33" :suppressCopyRowsToClipboard="true"
                             rowSelection="multiple" @grid-ready="gridReady" style="height:calc(100% - 45px)"
                             :defaultColDef=" defaultColDef
            " class="ag-theme-alpine" :rowData="table.dataList"
                             :columnDefs="tc" :localeText="localeText1"></AgGridVuesCopys>
            <paginationCopys v-if="shenhebiaoji==1" :page-size-options="pagingList1" :total="total" show-total
                             show-jumper show-page-size
                             @change="PageSize" @page-size-change="change1" style="justify-content: center"
                             :page-size="size"
                             :current="page"/>
          </a-spin>
        </a-tab-pane>

        <a-tab-pane title="已审核" key="2">
          <a-spin :loading="pageData.pageLoading" tip="加载中" dot style="height: 100%; width: 100%; z-index: 999">
            <AgGridVuesCopys :rowHeight="33" :headerHeight="33" :suppressCopyRowsToClipboard="true"
                             rowSelection="multiple" @grid-ready="gridReady2" style="height: calc(100% - 45px);"
                             :defaultColDef="defaultColDef" class="ag-theme-alpine" :rowData="table.dataList"
                             :columnDefs="tc2" :localeText="localeText1"></AgGridVuesCopys>
            <paginationCopys v-if="shenhebiaoji==2" :page-size-options="pagingList1" :total="total" show-total
                             show-jumper show-page-size
                             @change="PageSize" @page-size-change="change1" style="justify-content: center"
                             :page-size="size"
                             :current="page"/>
          </a-spin>
        </a-tab-pane>
      </a-tabs>
    </template>
    <a-drawer ok-text="保存" cancel-text="关闭" :style="{ zIndex: 999 }" :mask-closable="false"
              :ok-loading="pageData.pageLoading" unmount-on-close popup-container=".arco-tabs-content" height="100%"
              :visible="pageData.showAdd" placement="bottom" @cancel="pageData.showAdd = false">
      <template #title>
        {{ pageData.isDetails == true ? '详情' : pageData.sideTitle }}
      </template>
      <!-- 基本信息 -->
      <template #footer>
        <a-button @click="cancelPop"> 关闭</a-button>
        <a-button type="primary" @click="sideOk" v-if="!pageData.isDetails"> 保存</a-button>
      </template>
      <div style="min-width: 1500px; overflow: auto" class="scrollbar">
        <el-scrollbar>
          <a-collapse :default-active-key="[1]">
            <a-collapse-item header="基本信息" :key="1">
              <a-form style="padding-left: 40px" size="mini" ref="formRef" layout="inline" :model="dataForm">
                <a-form-item :style="{ width: '325px' }" label-col-flex="100px" label="坯布编号"
                             field="greyCode" :rules="[{ required: true, message: '坯布编号必选' }]"
                             :disabled="pageData.isDetails">
                  <a-input :class="{ bacClass: true }" :style="{ width: '250px' }"
                           v-model="dataForm.greyCode"></a-input>
                </a-form-item>
                <a-form-item :style="{ width: '325px' }" label-col-flex="100px" label="是否本集团"
                             field="processType" :disabled="pageData.isDetails"
                             :rules="[{ required: true, message: '是否本集团必选' }]"
                             :validate-trigger="['change', 'blur']">
                  <a-select popup-container="html" :style="{ width: '250px' }" :class="{ bacClass: true }"
                            v-model="dataForm.processType">
                    <a-option :value="0">本集团</a-option>
                    <a-option :value="1">外加工</a-option>
                  </a-select>
                </a-form-item>
                <a-form-item :style="{ width: '1372px' }" label-col-flex="100px" label="坯布名称"
                             field="grayFabricName" :rules="[{ required: true, message: '坯布名称必填' }]"
                             :validate-trigger="['change', 'blur']" :disabled="pageData.isDetails">
                  <a-input :class="{ bacClass: true }" v-model="dataForm.grayFabricName"/>
                </a-form-item>
                <a-form-item :style="{ width: '325px' }" label-col-flex="100px" label="布类" field="mercery"
                             :disabled="pageData.isDetails">
                  <a-select popup-container="html" :class="{ bacClass: true }" allow-clear allow-search
                            @search="blSelect"
                            v-model="dataForm.mercery" @focus="focusBl">
                    <a-option v-for="item in blList" :value="item.merceryName">{{ item.merceryName }}
                    </a-option>
                  </a-select>
                </a-form-item>
                <a-form-item :style="{ width: '325px' }" label-col-flex="100px" label="成分"
                             field="ingredient" :disabled="pageData.isDetails">
                  <a-input :class="{ bacClass: true }" v-model="dataForm.ingredient"/>
                </a-form-item>
                <a-form-item :style="{ width: '325px' }" label-col-flex="100px" label="面料种类"
                             field="fabricType" :disabled="pageData.isDetails">
                  <a-select popup-container="html" :class="{ bacClass: true }" allow-clear allow-search
                            @search="fabricTypeSelect" v-model="dataForm.fabricType" @focus="fabricTypeFocus">
                    <a-option v-for="item in fabricTypeList" :value="item.fabricType">
                      {{ item.fabricType }}
                    </a-option>
                  </a-select>
                </a-form-item>
                <a-form-item :style="{ width: '325px' }" label-col-flex="100px" label="成品门幅"
                             field="finishedLimit" :disabled="pageData.isDetails">
                  <a-input :class="{ bacClass: true }" v-model="dataForm.finishedLimit"/>
                </a-form-item>

                <a-form-item :style="{ width: '325px' }" label-col-flex="100px" label="成品克重"
                             field="finishedWeight" :disabled="pageData.isDetails">
                  <a-input :class="{ bacClass: true }" v-model="dataForm.finishedWeight"/>
                </a-form-item>
              </a-form>
            </a-collapse-item>
            <!-- 工艺信息 -->
            <a-collapse-item header="工艺信息" :key="2">
              <a-form style="padding-left: 40px" size="mini" ref="formRef1" layout="inline" :model="dataForm">
                <a-form-item :style="{ width: '325px' }" label-col-flex="100px" label="寸数"
                             field="dimensionFigure" :disabled="pageData.isDetails">
                  <a-select popup-container="html" :class="{ bacClass: true }" v-model="dataForm.dimensionFigure"
                            @search="searchNeedleCountList" :filter-option="false" allow-search allow-clear
                            @change="changeNeedleCount" @focus="focusNeedleCountList">
                    <a-option v-for="item in pageData.needleCountList" :value="item['model']">{{
                        item['model']
                      }}
                    </a-option>
                  </a-select>
                </a-form-item>
                <a-form-item :style="{ width: '325px' }" label-col-flex="100px" label="针数"
                             field="needleCount" :disabled="pageData.isDetails">
                  <a-input v-model="dataForm.needleCount" :class="{ bacClass: true }" disabled/>
                </a-form-item>

                <a-form-item :style="{ width: '325px' }" label-col-flex="100px" label="总针数"
                             field="sumNeedleCount" :disabled="pageData.isDetails">
                  <a-input v-model="dataForm.sumNeedleCount" :class="{ bacClass: true }" disabled/>
                </a-form-item>
                <a-form-item :style="{ width: '325px' }" label-col-flex="100px" label="颜色属性"
                             field="colorAttribute" :disabled="pageData.isDetails">
                  <a-select popup-container="html" :class="{ bacClass: true }" v-model="dataForm.colorAttribute"
                            @search="searchColorAttribute" :filter-option="false" allow-search allow-clear
                            @focus="focusColorAttribute">
                    <a-option v-for="item in pageData.colorAttributeList"
                              :value="item['colorattribute']">{{
                        item['colorattribute']
                      }}
                    </a-option>
                  </a-select>
                </a-form-item>
              </a-form>
            </a-collapse-item>
          </a-collapse>
        </el-scrollbar>
      </div>
    </a-drawer>
  </pageTabelLayout>
</template>


<script lang="ts" setup>
import {post, get} from '@/api/http'
import {useTable, useRowKey, useTableColumn, usePagination, useRowSelection} from '@/hooks/table'
import emitter from '@/hooks/useEventBus'
import {ref, reactive, onMounted, toRefs, watch, toRaw} from 'vue'
import Toolbar from '@/components/Toolbar.vue'
import {Button, Form, Message, Modal} from '@arco-design/web-vue'
import {FormInstance} from '@arco-design/web-vue/es/form'
import {log} from 'echarts/types/src/util/log'

import {localeText} from '@/api/aggridZw'
import {pagingList} from '@/api/paging'
import {indexOf} from 'lodash'
import usePermission from '@/store/modules/permission'
import {simplifyMessages} from '@/api/messageSimplification'

interface Firm {
  name: string
  id: number
}

interface RawMaterialsList {
  orderMachineType: any
  circulationGap: any
  exploitCode: string | undefined
  shipperUnits: string | undefined
  activeOutput: number | undefined
  clothKindOfName: string | undefined
  loomRevolution: number | undefined
  yarnCountCode: string | undefined
  sebificDuctName: string | undefined
  id: number | undefined | string
  starts: string | undefined
  yarnCountCategory: string | undefined
  playingCards: string | undefined
  updateName: string | undefined
  greyCode: string | undefined
  inventoryLowerLimit: string | undefined
  beadJuggle: string | undefined
  knittingNeedleType: string | undefined
  productKind: string | undefined
  unit: string | undefined
  versions: string | undefined
  associatedGoods: string | undefined
  dimensionFigure: any
  grade: string | undefined
  createName: string | undefined
  colorAccording: string | undefined
  needleType: string | undefined
  englishName: string | undefined
  weaverPrice: number
  machineUnit: any
  weavingDamage: any
  actualYarn: any
  yarnCountIngredient: string | undefined
  remark: string | undefined
  productTime: any
  measuredYarnCount: string | undefined
  fabricType: string | undefined
  alwaysGoes: number | undefined
  needleCount: any
  feature: string | undefined
  mercery: string | undefined
  sumNeedleCount: any
  colorGroup: any
  machineType: string | undefined
  deleteState: number | undefined
  outsideProcessingClient: string | undefined
  ingredient: string | undefined
  englishIngredient: string | undefined
  weavingNote: string | undefined
  chineseIngredient: string | undefined
  yarnSource: string | undefined
  staple: string | undefined
  yarnKind: string | undefined
  stockNature: string | undefined
  sYarnProperty: string | undefined
  danielCoefficient: string | undefined
  yarnCountProportion: any
  inventoryDivisionMachine: string | undefined
  colorAttribute: string | undefined
  theoryCapacity: number | undefined
  updateTime: string | undefined
  grayFabricName: string | undefined
  drawnNeedleState: number | undefined | string
  scutchingState: any
  putOnRecordsCode: string | undefined
  yarnCountName: string | undefined
  createTime: string | undefined
  organization: string | undefined
  commodityState: string | undefined
  category: string | undefined
  inventoryUpperLimit: string | undefined
  popularizeCommodity: string | undefined
  finishedLimit: string | undefined
  finishedWeight: string | undefined
  colourNumber: number | undefined
  models: string | undefined
  processType: number | undefined
  rubberTube: any
  checkUnits: any
  perchPrice: any
  perchUnits: any
  yarnLength: any
  theoreticalYield: any
}


const total = ref(0)
const page = ref(1)
const size = ref(10)

function PageSize(val: any) {
  page.value = val
  doRefresh()
}

function change1(val: any) {
  size.value = val
  doRefresh()
}

const headerShow = ref<boolean>(true)
const ylList = ref<any[]>()

const pageData = reactive<{
  gcList: Firm[]
  showAdd: boolean
  pageLoading: boolean
  sideTitle: string
  dropDownData: any
  dropDownData1: any
  dropDownData2: any
  dropDownData3: any
  dropDownData4: any
  codeList: []
  nameList: []
  nameList1: []
  ggList: []
  flList: []
  needleCountList: any[]
  machineTypeList: any[]
  colorAttributeList: any[]
  unitList: any[]
  spRowList: any[]
  rHeight: number | undefined
  zuzhiList: any[]
  ylRowList: any[]
  materialsName: any
  rawmaterialCode: any
  yarnCount: any
  materialsNameList: any[]
  rawmaterialCodeList: any[]
  yarnCountList: any[]
  zhong: any
  yin: any
  isDetails: boolean
  cfPjList: any[]
  ylCfIdList: any[]
  psDataList: any[]
  wuliaoname: any[]
  isEdit: boolean
  btnList1: any[]
  btnList2: any[]
  isEdit1: boolean
  isEdit2: boolean
  isInfo1: boolean
  isInfo2: boolean
  yarnUnitsList: any[]
  wayList: any[]
}>({
  isEdit: false,
  btnList1: [],
  btnList2: [],
  isEdit1: false,
  isEdit2: false,
  isInfo1: false,
  isInfo2: false,
  gcList: [],
  showAdd: false,
  pageLoading: false,
  sideTitle: '新增坯布',
  dropDownData: '',
  dropDownData1: '',
  dropDownData2: '',
  dropDownData3: '',
  dropDownData4: '',
  codeList: [],
  nameList: [],
  nameList1: [],
  ggList: [],
  flList: [],
  needleCountList: [],
  machineTypeList: [],
  colorAttributeList: [],
  unitList: [],
  spRowList: [],
  rHeight: 0,
  zuzhiList: [],
  ylRowList: [],
  materialsName: '',
  rawmaterialCode: '',
  yarnCount: '',
  materialsNameList: [],
  rawmaterialCodeList: [],
  yarnCountList: [],
  zhong: '',
  yin: '',
  isDetails: false,
  cfPjList: [],
  ylCfIdList: [],
  psDataList: [],
  wuliaoname: [] as any,
  yarnUnitsList: [],
  wayList: []
})
let allDataList: any[] = []

function doRefresh() {
  pageData.pageLoading = true
  if (shenhebiaoji.value == 1) {
    post({
      url: '/pdm/GreyInformation/selectPage',
      data: {
        page: page.value,
        size: size.value,
        deleteState: 0,
        greyCode: pageData.dropDownData,
        grayFabricName: pageData.dropDownData2,
        productKind: pageData.dropDownData4,
        auditState: 0,
      },
    })
        .then(({data, code}: any) => {
          if (code === 200) {
            gridOption.value.setRowData(data.list)
            table.handleSuccess(data.list)
            total.value = data.total
            allDataList = data.list
          }
        })
        .catch(console.log)
        .finally(() => {
          pageData.pageLoading = false
        })
  } else {
    post({
      url: '/pdm/GreyInformation/selectPage',
      data: {
        page: page.value,
        size: size.value,
        deleteState: 0,
        greyCode: pageData.dropDownData,
        grayFabricName: pageData.dropDownData2,
        productKind: pageData.dropDownData4,
        auditState: 1,
      },
    })
        .then(({data, code}: any) => {
          if (code === 200) {
            gridOption2.value.setRowData(data.list)
            table.handleSuccess(data.list)
            total.value = data.total
            allDataList = data.list
          }
        })
        .catch(console.log)
        .finally(() => {
          pageData.pageLoading = false
        })
  }
}

const {selectedRowKeys, onSelectionChange} = useRowSelection()

const pagination = usePagination(doRefresh)
const table = useTable()
const rowKey = useRowKey('id')
const tableColumns = useTableColumn([
  {
    title: '坯布编号',
    key: 'greyCode',
    dataIndex: 'greyCode',
    width: 150,
  },
  {
    title: '坯布名称',
    key: 'grayFabricName',
    dataIndex: 'grayFabricName',
    width: 150,
  },

  {
    title: '针数',
    key: 'needleCount',
    dataIndex: 'needleCount',
    width: 150,
  },
  {
    title: '布类',
    key: 'mercery',
    dataIndex: 'mercery',
    width: 150,
  },
  {
    title: '寸数',
    key: 'dimensionFigure',
    dataIndex: 'dimensionFigure',
    width: 150,
  },
  {
    title: '总针数',
    key: 'sumNeedleCount',
    dataIndex: 'sumNeedleCount',
    width: 150,
  },
  {
    title: '颜色属性',
    key: 'colorAttribute',
    dataIndex: 'colorAttribute',
    width: 150,
  },

  {
    title: '面料种类',
    key: 'fabricType',
    dataIndex: 'fabricType',
    width: 150,
  },
  {
    title: '布类',
    key: 'mercery',
    dataIndex: 'mercery',
    width: 150,
  },
  {
    title: '成品门幅',
    key: 'finishedLimit',
    dataIndex: 'finishedLimit',
    width: 150,
  },
  {
    title: '成品克重',
    key: 'finishedWeight',
    dataIndex: 'finishedWeight',
    width: 150,
  },
  {
    title: '编辑',
    key: 'edit',
    dataIndex: 'edit',
    slotName: 'edit',
    width: 150,
    fixed: 'right',
  },
])
const dataForm = reactive<any>({
  orderMachineType: '',
  exploitCode: '',
  shipperUnits: '',
  activeOutput: 0,
  clothKindOfName: '',
  loomRevolution: 0,
  yarnCountCode: '',
  sebificDuctName: '',
  id: '',
  starts: '',
  yarnCountCategory: '',
  playingCards: '',
  updateName: '',
  greyCode: '',
  inventoryLowerLimit: '',
  beadJuggle: '',
  knittingNeedleType: '',
  productKind: '',
  unit: '',
  versions: '',
  associatedGoods: '',
  dimensionFigure: 0,
  grade: '',
  createName: '',
  colorAccording: '',
  needleType: '',
  englishName: '',
  weaverPrice: 0,
  machineUnit: 0,
  weavingDamage: 0,
  actualYarn: 0,
  yarnCountIngredient: '',
  remark: '',
  productTime: '',
  measuredYarnCount: '',
  fabricType: '',
  alwaysGoes: 0,
  needleCount: 0,
  feature: '',
  mercery: '',
  sumNeedleCount: null,
  colorGroup: '',
  machineType: '',
  deleteState: 0,
  outsideProcessingClient: '',
  ingredient: '',
  englishIngredient: '',
  weavingNote: '',
  chineseIngredient: '',
  yarnSource: '',
  staple: '',
  yarnKind: '',
  stockNature: '',
  sYarnProperty: '',
  danielCoefficient: '',
  yarnCountProportion: 0,
  inventoryDivisionMachine: '',
  colorAttribute: '',
  theoryCapacity: 0,
  updateTime: '',
  grayFabricName: '',
  drawnNeedleState: 2,
  scutchingState: '',
  putOnRecordsCode: '',
  yarnCountName: '',
  createTime: '',
  organization: '',
  commodityState: '',
  category: '',
  inventoryUpperLimit: '',
  circulationGap: '',
  popularizeCommodity: '',
  finishedLimit: '',
  finishedWeight: '',
  colourNumber: 0,
  models: '2',
  processType: 1,
  rubberTube: '',
  checkUnits: '',
  perchPrice: 0,
  perchUnits: '',
  yarnLength: '',
  theoreticalYield: 0
})
// 针数下拉框
const focusNeedleCountList = () => {
  getNeedleCountList({smallNumber: ''})
}

// 颜色属性
const focusColorAttribute = () => {
  getColorAttributeList({colorattribute: ''})
}

//下拉数据  坯布编号
const options = ref<any>(pageData.codeList)
const loading = ref(false)
const handleSearch = (value: any) => {
  if (value) {
    const ob = {greyCode: value}
    loading.value = true

    selCxAll(ob)
    options.value = pageData.codeList
    loading.value = false
  } else {
    options.value = []
  }
}

//下拉框查询 坯布编号
function selCxAll(val: any) {
  post({
    url: 'product/Rawmaterial/getGreyDrop',
    data: val,
  }).then(({data, code}: any) => {
    if (code === 200) {
      // (data as string[]).splice(0, 0, "全部");
      pageData.codeList = data
    } else {
      Message.error({
        content: '查询失败！',
        duration: 5000,
      })
    }
  })
}


// 针数下拉框
const searchNeedleCountList = (value: any) => {
  if (value) {
    const ob = {smallNumber: value}
    loading.value = true
    getNeedleCountList(ob)
    options.value = pageData.needleCountList
    loading.value = false
  } else {
    options.value = []
  }
}
const getNeedleCountList = (val: any) => {
  post({
    url: 'pdm/GreyInformation/getnumber',
    data: val,
  }).then(({data, code}: any) => {
    if (code === 200) {
      // (data as string[]).splice(0, 0, "全部");
      pageData.needleCountList = data
    } else {
      Message.error({
        content: '查询失败！',
        duration: 5000,
      })
    }
  })
}
// 颜色属性下拉框
const searchColorAttribute = (value: any) => {
  if (value) {
    const ob = {colorattribute: value}
    loading.value = true
    getColorAttributeList(ob)
    options.value = pageData.colorAttributeList
    loading.value = false
  } else {
    options.value = []
  }
}
// 颜色属性下拉框
const getColorAttributeList = (val: any) => {
  post({
    url: 'product/greyColorattribute/getFieldValue',
    data: val,
  }).then(({code, data}: any) => {
    if (code === 200) {
      pageData.colorAttributeList = data
    } else {
      Message.error({
        content: '查询失败',
        duration: 5000,
      })
    }
  })
}

const ylSelect = (val: any) => {
  post({
    url: 'product/Rawmaterial/getInfo',
    data: {
      materialsName: val,
    },
  }).then((res) => {
    if (res.code === 200) {
      ylList.value = res.data
    }
  })
}
onMounted(() => {
  // 切换tap到本页面执行的方法
  emitter.on('GreyFabricListDemo', () => {
    selCxAll({})
    doRefresh()

    //根据账号类型判断是否本集团
  })
  // getwuliao({ materialName: '',auditState:1})
  pageData.rHeight = document.getElementsByClassName('arco-tabs-content')[0]?.clientHeight
  //弹出层的高
  if (pageData.rHeight !== undefined) {
    pageData.rHeight = pageData.rHeight - 100
  }
  window.addEventListener('resize', () => {
    pageData.rHeight = document.getElementsByClassName('arco-tabs-content')[0]?.clientHeight
    //弹出层的高
    if (pageData.rHeight !== undefined) {
      pageData.rHeight = pageData.rHeight - 100
    }
  })
})
//查询
const selectHandler = () => {
  page.value = 1
  doRefresh()
}
const queryData = reactive({
  firm: '',
})
const addHandler = () => {
  for (var key in dataForm) {
    if (key == "id") {
      dataForm[key] = null;
    } else {
      dataForm[key] = "";
    }
  }
  dataForm.processType = 1
  pageData.showAdd = true
  pageData.sideTitle = '新增坯布'
}
let xhCol = ref<any[]>([])
const ewsj = ref<any>([])
//修改 record（本行数据）
const editHandler = (record: any, num: any) => {
  for (var key in record) {
    dataForm[key] = record[key]
  }
  if (num == 2) {
    pageData.isDetails = true
    pageData.showAdd = true
  } else {
    pageData.isDetails = false
    pageData.showAdd = true
    pageData.sideTitle = '修改坯布'
  }
}

const changeNeedleCount = (val: any) => {
  dataForm.needleCount = undefined
  dataForm.dimensionFigure = undefined
  dataForm.sumNeedleCount = undefined

  pageData.needleCountList.forEach(function (o: any) {
    if (o['model'] == val) {
      dataForm.needleCount = o['numberThreads']
      dataForm.dimensionFigure = o['smallNumber']
      dataForm.sumNeedleCount = o['sumNeedleNum']
    }
  })
}

const formRef = ref<FormInstance>()
const formRef1 = ref()
const sideOk = () => {
  pageData.pageLoading = true
  formRef.value?.validate().then((err) => {
    if (!err) {
      if (pageData.sideTitle === '新增坯布') {
        post({
          url: '/pdm/GreyInformation/insert',
          data: [dataForm]
        })
            .then((res: any) => {
              if (res.code === 200) {
                Message.success({
                  content: '新增成功',
                  duration: 5000,
                })
                pageData.showAdd = false
                pageData.pageLoading = false
                doRefresh()
              } else {
                Message.error({
                  content: res.message,
                  duration: 5000,
                })
              }
            })
            .finally(() => {
              pageData.pageLoading = false
            })
      } else {
        post({
          url: 'pdm/GreyInformation/update',
          data: [dataForm]
        })
            .then(({data, code, message}: any) => {
              if (code === 200) {
                formRef.value?.resetFields()
                Message.success({
                  content: '修改成功',
                  duration: 5000,
                })
                doRefresh()
                pageData.showAdd = false
                pageData.pageLoading = false
              } else {
                Message.error({
                  content: message,
                  duration: 5000,
                })
              }
            })
            .finally(() => {
              pageData.pageLoading = false
            })
      }
    }
  })

}
const deleteHandler = () => {
  if (shenhebiaoji.value == 1) {
    if (gridOption.value.getSelectedRows().length === 0) {
      Message.error('请先勾选')
      return
    }
    Modal.confirm({
      title: '系统提示',
      content: '确认删除选中的数据?',
      draggable: true,
      onOk() {
        pageData.pageLoading = true
        post({
          url: 'pdm/GreyInformation/delete',
          data: gridOption.value.getSelectedRows().map((o: any) => {
            return o.id
          }),
        })
            .then(({code, data, message}: any) => {
              if (code === 200) {
                Message.success({
                  content: '删除成功',
                  duration: 5000,
                })
                pagination.page = 1
                doRefresh()
              } else {
                Message.error({
                  content: message,
                  duration: 5000,
                })
              }
            })
            .finally(() => {
              pageData.pageLoading = false
            })
      },
    })
  }
}

const gridOption = ref()
const gridReady = (params: any) => {
  gridOption.value = params.api
}
const gridOption2 = ref()
const gridReady2 = (params: any) => {
  gridOption2.value = params.api
}
const numb = reactive<{ row: number[]; col: number }>({
  row: [1, 1],
  col: 1,
})
const blList = ref<any[]>([])
const focusBl = () => {
  post({
    url: 'product/mercery/getList',
    data: {
      merceryName: '',
      deleteState: '0',
    },
  }).then(({code, data}) => {
    if (code === 200) {
      blList.value = data
    }
  })
}
const blSelect = (v: string) => {
  post({
    url: 'product/mercery/getList',
    data: {
      merceryName: v,
      deleteState: '0',
    },
  }).then(({code, data}) => {
    if (code === 200) {
      blList.value = data
    }
  })
}
const szList = ref<any[]>([])
const psjpb = ref<any>()

//排纱
let psList = ref<any[]>([])
const visible = ref(false)

//关闭弹窗时初始化数据
const cancelPop = () => {
  pageData.showAdd = false
  psList.value = []
  xhCol.value = []
  pageData.ylCfIdList = []
  theoryPrice.value = 0
  machineUnit.value = 0
}
let tc: any[] = tableColumns.map((o: any) => {
  let obj = {
    headerName: o.title,
    field: o.key,
    pinned: o['fixed'],
    tooltipField: o.key,
  }
  if (o.slotName === 'edit') {
    obj['resizable'] = false
    obj['filter'] = false
    obj['sortable'] = false
    obj['lockPosition'] = 'right'
    obj['width'] = 150
    obj['cellRenderer'] = {
      template: `
        <a-space>
          <a-tag class="tagCss" @click="a" v-if="e">修改</a-tag>
          <a-tag class="tagCss" @click="b" v-if="f">详情</a-tag>
        </a-space>`,
      setup(props: any) {
        const a = () => {
          editHandler(props.params.data, 1)
        }
        const b = () => {
          editHandler(props.params.data, 2)
        }
        return {
          a,
          b,
          f: pageData.isInfo1,
          e: pageData.isEdit1,
        }
      },
    }
  }

  return obj
})

let tc2: any[] = tableColumns.map((o: any) => {
  let obj = {
    headerName: o.title,
    field: o.key,
    pinned: o['fixed'],
    tooltipField: o.key,
  }
  if (o.slotName === 'edit') {
    obj['resizable'] = false
    obj['filter'] = false
    obj['sortable'] = false
    obj['lockPosition'] = 'right'
    obj['width'] = 100
    obj['cellRenderer'] = {
      template: `
        <a-space>
          <a-tag class="tagCss" @click="b" v-if="f">详情</a-tag>
        </a-space>`,
      setup(props: any) {
        const a = () => {
          editHandler(props.params.data, 1)
        }
        const b = () => {
          editHandler(props.params.data, 2)
        }
        return {
          a,
          b,
          f: pageData.isInfo1,
        }
      },
    }
  }

  return obj
})
let a = [
  {
    showRowGroup: 'hide_def',
    headerName: '',
    checkboxSelection: true,
    headerCheckboxSelection: true,
    pinned: 'left',
    width: 50,
    resizable: false,
    filter: false,
    sortable: false,
    minWidth: 50,
    maxWidth: 50,
    lockPosition: 'left',
  },
]
tc = a.concat(tc)
tc2 = a.concat(tc2)
const defaultColDef = {
  sortable: true,
  resizable: true,
  filter: true,
  // flex: 1
}
//添加原料表格
let selectedRowKeysAddYl = ref()

const visible1 = ref(false)

//添加原料列表的表单数据
let ylData = ref({
  materialsName: '',
  rawmaterialCode: '',
  yarnCount: '',
  auditState: 1,
  processType: 1
})

const fabricTypeList = ref<any[]>([])
const fabricTypeLoading = ref(false)
const fabricTypeSelect = (value: any) => {
  if (value) {
    fabricTypeLoading.value = true
    getFabricTypeList(value)
    fabricTypeLoading.value = false
  }
}
const fabricTypeFocus = () => {
  getFabricTypeList('')
}
const getFabricTypeList = (val: any) => {
  post({
    url: 'product/pdFabric/getFieldValue',
    data: {
      fabricType: val,
      deleteState: 0,
    },
  }).then(({code, data}) => {
    if (code === 200) {
      fabricTypeList.value = data
    }
  })
}

const localeText1: any = ref(localeText)

const huiche = () => {
  doRefresh()
}


const duiqiheight = ref(35)
const xuanhuancihu = ref(1)
const shikaishu = ref(1)


const wuliaoname = ref([]) as any

const pagingList1: any = ref(pagingList)
const machineUnit = ref(0)
//根据账号判断是否为本集团
const shifoubenjituan = () => {
  get({
    url: '/admin/acl/user/getMemberIdByJwtToken',
    data: {},
  })
      .then((res: any) => {
        if (typeof res == 'string') {
          Message.error({
            content: '返回异常',
            duration: 5000,
          })
        }
        if (res.code === 200) {
          dataForm.processType = res.data.data.judgeGroup
          shifouxiugaibianhao.value = res.data.data.judgeGroup
        } else {
          Message.error({
            content: res.message,
            duration: 5000,
          })
        }
      })
      .finally(() => {
      })
}

const id = ref(null)
const shabilist = ref([])
const isshow = ref(true)
const theoryPrice = ref(0)


//判断账号是本集团还是外加工，判断编号是否可以修改
const shifouxiugaibianhao = ref(null)
const xuanzepaisanjiaolist = ref([]) as any
const paishabiaoji = ref(0)

const buleibianhao = ref('')
const gongnengbianhao = ref('')
const shazhibianhao = ref('')
const handoff = (val: any) => {
  shenhebiaoji.value = val
  doRefresh()
}
const shenhebiaoji = ref(1)
const shenhe = (val: any) => {
  if (val == '待审核') {
    if (gridOption.value.getSelectedRows().length === 0) {
      Message.error('请先勾选')
      return
    }
    var shenhelist = [] as any
    gridOption.value.getSelectedRows().map((o: any) => {
      var obj = {
        id: o.id,
        auditState: 1,
      }
      shenhelist.push(obj)
    })
    Modal.confirm({
      title: '系统提示',
      content: '确认审核选中的数据?',
      draggable: true,
      onOk() {
        pageData.pageLoading = true
        post({
          url: 'pdm/GreyInformation/update',
          data: shenhelist,
        }).then(({data, code, message}: any) => {
          if (code === 200) {
            Message.success({
              content: simplifyMessages(message),
              duration: 500,
            })
            doRefresh()
          } else {
            Message.error({
              content: simplifyMessages(message),
              duration: 5000,
            })
          }
        })
      },
    })

  } else {
    if (gridOption2.value.getSelectedRows().length === 0) {
      Message.error('请先勾选')
      return
    }
    var shenhelist = [] as any
    gridOption2.value.getSelectedRows().map((o: any) => {
      var obj = {
        id: o.id,
        auditState: 0,
      }
      shenhelist.push(obj)
    })
    Modal.confirm({
      title: '系统提示',
      content: '确认反审选中的数据?',
      draggable: true,
      onOk() {
        pageData.pageLoading = true
        post({
          url: 'pdm/GreyInformation/update',
          data: shenhelist,
        }).then(({data, code, message}: any) => {
          if (code === 200) {
            Message.success({
              content: simplifyMessages(message),
              duration: 500,
            })
            doRefresh()
          } else {
            Message.error({
              content: simplifyMessages(message),
              duration: 5000,
            })
          }
        })
      },
    })
  }
}

const crossMemo = ref('')
const huancunpanduanziduan = ref('')


const permissionStore = usePermission()
if (shenhebiaoji.value == 1) {
  if (permissionStore.hasPermisson('pblb.dclxg')) {
    pageData.isEdit1 = true
  }
  if (permissionStore.hasPermisson('pblb.dclxq')) {
    pageData.isInfo1 = true
  }
} else {
  if (permissionStore.hasPermisson('pblb.yclxq')) {
    pageData.isInfo1 = true
  }
}

const caikoupaizhen = ref([]) as any


</script>
<style scoped lang="less">
:deep(.ag-cell) {
  border-right: 1px solid #dde2eb;
}

:deep(.ag-header-cell) {
  border-right: 1px solid #dde2eb;
}

:deep(.ag-cell-value) {
  user-select: initial;
  -moz-user-select: text;
  -ms-user-select: text;
  -webkit-user-select: text;
}
</style>